import passport from 'koa-passport'
import { Strategy } from 'passport-local'

import { User } from '../models'

passport.serializeUser(
    (user, done) => {
        done(null, user.uid)
    })

passport.deserializeUser(
    async(uid, done) => {
        try {
            const user = await User.findOne({ 'uid': uid })
            done(null, user)
        } catch (err) {
            done(err)
        }
    })

passport.use('local', new Strategy({},
    async({}, done) => {
        try {
            return await User.find({ where: {}, limit: 20 })
        } catch (err) {
            return done(err)
        }
    }
))